package ua.org.extjsbuilder.parser.runtime.builder;

import java.io.EOFException;

import ua.org.extjsbuilder.parser.runtime.UnparsedToken;

final class GlobalInterpreter extends CyclesInterpreter {
	
	GlobalInterpreter(UnparsedToken start){
		super(start);
	}
	
	public GlobalInterpreter(UnparsedToken start, int pos) {
		this(start);
		this.pos = pos;
	}

	boolean next(){
		try {
			boolean res = super.next();
			if(state == EXPECT_OPERATOR){
				ExpressionsInterpreter intr = new ExpressionsInterpreter(token, pos);
				intr.setState(this,true);
				intr.skipWhiteSpaces();
				intr.analyzeOperator();
				setState(intr,true);
				if(data==null||is(';')){
					state = LEFT_START;
					pos++;
				}
			}
			
			return res;
		}
		catch(EOFException ex){
			if(state!=LEFT_START)err("Unexpected file end");
			return false;
		}
	}

	public char chr() {
		return data[pos];
	}
}
